
import React, { Component } from 'react'

export default class Son extends Component {

  constructor(props){
    super(props);
    this.parent = null;
  }

  toSon(str) {
    console.log("toSon", str);
  }

  componentDidMount() {
    this.props.onRef(this);
  }

  toParent=()=>{
    this.parent.sonToParent("hello，我是儿子");
  }

  render() {
    return (
      <>
        <div>Son</div>
        <p>this.props.title:{this.props.title}</p>
        <input type="button" value=" 传给父 " onClick={this.toParent} />
      </>
    )
  }
}
